<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ITOUC 后台管理</title>

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link id="layuicss-layer" rel="stylesheet" href="/layui/css/modules/layer/default/layer.css">
    <link id="layuicss-layuiAdmin" rel="stylesheet" href="/css/admin.css">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="/layui/lay/modules/layer.js" charset="UTF-8"></script>
</head>
<body layadmin-themealias="default" class="layui-layout-body">
<div id="LAY_app" class="layadmin-tabspage-none">
    <link rel="stylesheet" href="/css/login.css" media="all">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>ITOUC Admin</h2>
                <p>ITOUC 后台管理系统</p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-email"></label>
                    <input type="text" name="username" id="LAY-user-login-email" lay-verify="required|email" placeholder="邮箱" class="layui-input">
                </div>
                <div class="layui-form-item" style="display:none;">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"></label>
                    <input name="token" id="LAY-user-login-token" lay-verify="required" placeholder="验证码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button id="admin-login-button" class="layui-btn layui-btn-fluid"  lay-filter="LAY-user-login-submit">登 录</button>
                </div>
            </div>
        </div>
        <div class="layui-trans layadmin-user-login-footer">

            <p>© 2019 <a href="http://www.itstudio.club" target="_blank">爱特工作室</a></p>
        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<style id="LAY_layadmin_theme">.layui-side-menu,.layadmin-pagetabs .layui-tab-title li:after,.layadmin-pagetabs .layui-tab-title li.layui-this:after,.layui-layer-admin .layui-layer-title,.layadmin-side-shrink .layui-side-menu .layui-nav>.layui-nav-item>.layui-nav-child{background-color:#20222A !important;}.layui-nav-tree .layui-this,.layui-nav-tree .layui-this>a,.layui-nav-tree .layui-nav-child dd.layui-this,.layui-nav-tree .layui-nav-child dd.layui-this a{background-color:#009688 !important;}.layui-layout-admin .layui-logo{background-color:#20222A !important;}</style>

<script>
    layui.use(['jquery'], function(){
        var $ = layui.$;

        $("#admin-login-button").click(function () {
            var load = layer.load(2);
            if (valid()){
                var email = document.getElementById("LAY-user-login-email").value;
                $.ajax({
                    url:        '/admin/login/captcha?email=' + email,
                    complete    :function (result) {
                        layer.close(load);
                        var code = result.responseJSON.status;
                        if (code == 200){
                            layer.prompt({
                                    title: '验证码'
                                }, function (value, index, elem) {
                                    layer.close(index);
                                    var load = layer.load(2);
                                    var data = {
                                        'email':document.getElementById("LAY-user-login-email").value,
                                        'captcha': value
                                    }
                                    $.ajax({
                                        url: '/admin/login',
                                        data: data,
                                        type: 'POST',
                                        complete: function (result) {
                                            layer.close(load);
                                            var code = result.responseJSON.status;
                                            var message = result.responseJSON.message;
                                            layer.msg(message);
                                            if (code == 200) {
                                                window.location.href="/admin/index";
                                            }
                                        }
                                    })
                                }
                            )
                        }else {
                            showResult(result.responseJSON.message);
                        }
                    }
                })
            }
        })
        function valid() {
            var email = document.getElementById("LAY-user-login-email").value;
            if (email == null || email == ""){
                showResult("请填写邮箱");
                return false;
            }
            return true;
        }
        //显示结果
        function showResult(text) {
            layer.msg("<div style=\"padding: 20px 100px;\">"+ text + "</div>", {
                time: 8000, //8s后自动关闭
                btn: ['明白了'],
                shade: 0.3,
                yes: function (index, layero) {
                    layer.closeAll();
                }
            });
        }
    })
</script>

</body>
</html>